package com.example.menu;

import androidx.appcompat.app.AppCompatActivity;
import androidx.constraintlayout.widget.ConstraintLayout;

import android.os.Bundle;
import android.view.ContextMenu;
import android.view.MenuItem;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.example.menu.databinding.ActivityMainBinding;

public class MainActivity extends AppCompatActivity{
    private ActivityMainBinding binding;
    TextView emplist=null;
    String number;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        binding = ActivityMainBinding.inflate(getLayoutInflater());
        ConstraintLayout root = binding.getRoot();
        setContentView(root);

        emplist=(TextView)super.findViewById(R.id.btn_copy);
        registerForContextMenu(emplist);
    }

    @Override
    public boolean onContextItemSelected(MenuItem item) {
        if (item.getItemId() == R.id.item_clear) {
            Toast.makeText(this, "清空", Toast.LENGTH_SHORT).show();
        } else if (item.getItemId() == R.id.item_copy) {
            Toast.makeText(this, "拷贝", Toast.LENGTH_SHORT).show();
        } else if(item.getItemId() == R.id.item_paste)
            Toast.makeText(this, "粘贴", Toast.LENGTH_SHORT).show();
        return super.onContextItemSelected(item);
    }
    @Override
    public void onCreateContextMenu(ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuInfo) {
        super.onCreateContextMenu(menu, v, menuInfo);
        if (v.getId()==R.id.btn_copy){
            getMenuInflater().inflate(R.menu.content_menu,menu);
        }
    }
    }



